package com.example.service.impl;

import com.example.dao.ArcUserDao;
import com.example.common.IdCardUtil;
import com.example.entity.ArcUserEntity;
import com.example.service.ArcUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.concurrent.*;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;


@Slf4j
@Service("arcUserService")
public class ArcUserServiceImpl extends ServiceImpl<ArcUserDao, ArcUserEntity> implements ArcUserService {
    @Autowired
    ArcUserDao arcUserDao;


    @Override
    public void delte(Integer max,Integer min) {
        List<ArcUserEntity> arcUserEntities = this.selectList(new EntityWrapper<ArcUserEntity>().gt("id",min).lt("id",max));

        int i = Runtime.getRuntime().availableProcessors();
        log.info("=========计算机核数========" + i);
        // 获取系统CPU个数，线程总数为CPU个数-1
        ExecutorService fixedThreadPool = new ThreadPoolExecutor(i-1, i-1,
                60L, TimeUnit.SECONDS,
                new LinkedBlockingQueue());
        for (ArcUserEntity bailincode : arcUserEntities) {
            fixedThreadPool.execute(new DeleteUserThread(bailincode));
        }

    }


    public class DeleteUserThread implements Runnable {
        ArcUserEntity arcUserEntity;

        public DeleteUserThread(ArcUserEntity arcUserEntity) {
            this.arcUserEntity = arcUserEntity;
        }

        @Override
        public void run() {
            String idNo = arcUserEntity.getIdNo();
            if (null != idNo && !"女".equals(IdCardUtil.getGenderByIdCard(idNo))) {
                arcUserDao.deleteById(arcUserEntity.getId());
                log.info("=======删除用户成功======" + idNo + "====id===" + arcUserEntity.getId());
            }
        }
    }
}
